import { createApp } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import 'virtual:uno.css'
import App from './App.vue'
import routes from './routes/index'
import './style/index.scss'
import { mountEvent } from './tools/event'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import ImageBox from '@/components/imageBox.vue'

const router = createRouter({
    history: createWebHistory(),
    routes
})

//全局前置守卫
router.beforeEach((to, from, next) => {
    // 路由发生变化时，滚动到页面顶部。
    window.scrollTo(0, 0)
    next()
})

const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)

const app = createApp(App)
app.component('ImageBox',ImageBox)
mountEvent(app)

app.use(router)
    .use(pinia)
    .mount('#app')
